package test.ground.springcache;

import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Service
@CacheConfig(cacheNames = "h1")
public class SpringCacheService implements Test1{


    @Cacheable("#p0")
    public Integer hello(String key){
//        如果当前有缓存，则内部方法进不来
        return g1(key);
    }

    private Integer g1(String key){
        return Integer.parseInt(key);
    }


    public void test_onApplicationEvent_1() throws IOException, InterruptedException {
        ExecutorService executor = Executors.newCachedThreadPool();
        executor.submit(new Runnable() {
            @Override
            public void run() {
                hello("11");
                System.out.println(2);
            }
        });
        Thread.sleep(100);

        hello("11");
    }

    @Cacheable("#p0")
    public Integer hello2(String key,boolean xx){
        return Integer.parseInt(key);
    }


    public static void main(String[] args) {
        System.out.println(1);
    }
}
